﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace be.metanous.mvvm.extensions
{
   
    [DebuggerStepThrough]
    public static class BitmapExtensions
    {

        public static BitmapSource CreateBitmapSource(this Bitmap bitmap)
        {
            if (bitmap == null) return null;

            return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
                                                         BitmapSizeOptions.FromWidthAndHeight(bitmap.Width, bitmap.Height));
        }

    }

}
